<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>Document</title>
    <style type="text/css">
        .ball {
            background: #f00;
            width: 10px;
            height: 10px;
            border-radius: 5px;
        }
        li {
            border: 1px solid #faf;
            margin: 5px;
            line-height: 30px;
            padding-left: 5px;
            font-style: 12px;
            width: 100%;
            list-style-type: none;
        }
        .v-enter,
        .v-leave-to{
            opacity: 0;
            transform: translateY(30px);
        }
        .v-enter-active,
        .v-leave-active {
            transition: all 1s ease;
        }
        /* 使用v-move和v-leave-active配合使用，实现列表后续的元素效果 */
        .v-move {
            transition: all 1s ease;
        }
        .v-leave-active {
            position: absolute;
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            <label>
                id:
                <input type="text" v-model="id">
            </label>
            <label>
                name:
                <input type="text" v-model="name" >
            </label>

            <input type="button" value="添加" v-on:click="add">
        </div>
            <!-- appear，是transition-group包含的元素一个入场效果 -->
            <!-- 如果直接使用ul包含以下元素，会发现transition-grounp会被渲染为span元素，不符合规范 -->
            <!-- 可以使用tag属性，规定该标签以ul渲染 -->
            <transition-group appear tag="ul">
                <li v-for="lis in list" v-bind:key="lis.id" v-on:click="del"> {{ lis.id }} --- {{ lis.name }}</li>
            </transition-group>
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                list: [
                    {id: 1, name: "a1"},
                    {id: 2, name: "b2"},
                    {id: 3, name: "c3"}
                ],
                id: "",
                name: ""
            },
            methods: {
                add: function() {
                    this.list.push({id: this.id, name: this.name})
                },
                del: function(i) {
                    this.list.splice(i, 1)
                }
            }
        });
    </script>
</body>

</html>